package com.chb.docter.controller.apis;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chb.docter.dto.PatientAllDto;
import com.chb.docter.mapper.PatientMapper;
import com.chb.docter.params.PatientQueryParams;
import com.chb.docter.service.CareHistoryService;
import com.chb.docter.service.PatientService;
import com.chb.docter.service.impl.CareHistoryServiceImpl;
import com.hos.entity.his.CareHistory;
import com.hos.entity.his.Patient;
import com.hos.entity.his.PatientFile;
import com.hos.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 陈海彬
 * @date: Created in 2023/12/12 14:47
 * @description: 患者controller
 * @modified By:
 * @version: 1.0
 */
@RestController
@RequestMapping("docter/api/patient")
@Api(value = "患者管理相关接口", tags = "患者管理相关接口")
@Slf4j
public class ApiPatientController {


    @Resource
    private PatientService patientService;

    @Resource
    private CareHistoryService careHistoryService;

    @ApiOperation(value = "根据身份证查询患者信息")
    @GetMapping("getPatientInfoByIdCar/{idCard}")
    public Result<Patient> getPatientInfoByIdCar(@PathVariable String idCard) {
        return new Result<>(200, "查询成功", patientService.getPatientInfoByIdCar(idCard));
    }


    @ApiOperation("分页查询患者列表信息")
    @PostMapping("listPatientForPage")
    public Result<Page<Patient>> listPatientForPage(@RequestBody PatientQueryParams params) {
        Page<Patient> page = patientService.listPatientForPage(params);
        return new Result<>(200, "查询成功", page);
    }

    @GetMapping("getPatientById/{patientId}")
    @ApiOperation("根据患者ID查询患者信息")
    public Result<Patient> getPatientById(@PathVariable String patientId) {
        return new Result<>(200, "查询成功", this.patientService.getPatientById(patientId));
    }

    @GetMapping("getPatientFileById/{patientId}")
    @ApiOperation("根据患者ID查询患者的档案信息")
    public Result<PatientFile> getPatientFileById(@PathVariable String patientId) {
        return new Result<>(200, "查询成功", this.patientService.getPatientFileById(patientId));
    }


    @GetMapping("getPatientAllMessageByPatientId/{patientId}")
    @ApiOperation("根据患者ID查询患者所有信息【基础，档案，病例】")
    public Result<List<CareHistory>> getPatientAllMessageByPatientId(@PathVariable String patientId) {
        return new Result<>(200, "查询成功", this.patientService.getPatientAllMessageByPatientId(patientId));
    }

    @GetMapping("getPatientInfo")
    @ApiOperation("获取患者信息")
    public Result<Patient> getPatientInfo() {
        return new Result<>(200, "查询成功", this.patientService.getPatientInfo());
    }

    @PostMapping("updateAvatar")
    @ApiOperation("修改患者头像信息")
    public Result<String> updateAvatar(@RequestBody MultipartFile file) {
        return new Result<>(200, "修改成功", this.patientService.updateAvatar(file));
    }

    @PutMapping("updatePatientInfo")
    @ApiOperation("修改患者信息")
    public Result<Patient> updatePatientInfo(@RequestBody Patient patient) {
        return new Result<>(200, "修改成功", this.patientService.updatePatientInfo(patient));
    }

    @GetMapping("/getPatientToken")
    @ApiOperation("根据患者查询患者所有信息")
    public Patient getPatientToken() {
        return careHistoryService.getAppPatientToken();
    }

    @ApiOperation("进行头像上传到阿里云")
    @PostMapping("upload")
    public Result<String> upload(@RequestBody MultipartFile file) {
        return new Result<>(200, "上传成功", this.patientService.upload(file));
    }
}